#include "window_common.h"

#if !defined(GKT_CONFIG_WINDOW_VOICE_MUTE_DISABLE) \
	|| !GKT_CONFIG_WINDOW_VOICE_MUTE_DISABLE

enum {
	WIDGET_ID_TITLE = 0,
	WIDGET_ID_SELECT,
	WIDGET_ID_CANCEL_OK,
	WIDGET_ID_MAX
};

static const gkt_widget_select_attr_u sc_window_voice_mute_widget_select_attr = {
	GKT_WIDGET_SELECT_SWITCH_ATTR(GKT_WIDGET_SELECT_SWITCH_TYPE_OPEN_CLOSE, 0),
};

GKT_WINDOW_WIDGET_DESCS_DEFINE(voice_mute) = {
	[WIDGET_ID_TITLE] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_MIDDLE | GKT_WIDGET_F_TITLE_MARK,
		WINDOW_FONT_NORMAL_SIZE, 
		WINDOW_TITLE_FG_COLOR, WINDOW_TITLE_BG_COLOR,
		0, 0, 
		WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_voice_mute_mode
	),
	[WIDGET_ID_SELECT] = GKT_WIDGET_SELECT_DESC(
		GKT_WIDGET_F_ALIGN_MIDDLE,
		WINDOW_FONT_LARGE_SIZE,
		WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		0, WINDOW_WIDGET_NORMAL_HEIGHT, 
		WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT*2,
		&sc_window_voice_mute_widget_select_attr
	),
	[WIDGET_ID_CANCEL_OK] = GKT_WIDGET_LABEL_DESC(
		GKT_WIDGET_F_ALIGN_MIDDLE,
		WINDOW_FONT_NORMAL_SIZE, WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		0, WINDOW_WIDGET_NORMAL_HEIGHT * (WINDOW_NORMAL_ROWS - 1), 
		WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_cancel_ok
	),
};

typedef struct _window_voice_mute {
	uint32_t	select_value;
} window_voice_mute_s;
static window_voice_mute_s s_window_voice_mute;

static void window_voice_mute_complete(uint32_t state)
{
	gkt_window_voice_set_mute((int)state);

	window_dialog_show_big_prompt(WINDOW_DIALOG_HINT_SUCCESS,
			WINDOW_TEXT_ID_voice_mute_mode,
			state ? WINDOW_TEXT_ID_already_opened : WINDOW_TEXT_ID_already_closed, 
			WINDOW_VOICE_COMBINED_ID(set_success));
}

static int window_voice_mute_event_handler(
				uint32_t major_type, uint32_t minor_type, 
				uint32_t widget_id, uint32_t data)
{
	int retval = GKT_EVENT_HANDLE_CONTINUE;

	switch(major_type){
		case	GKT_EVENT_WINDOW:
			if(minor_type == GKT_WINDOW_INIT)
				s_window_voice_mute.select_value = data;
			else if(minor_type == GKT_WINDOW_ACTIVE) {
				uint32_t active_1st = data;
				if (active_1st) {
					if (s_window_voice_mute.select_value < WINNDOW_SWITCH_ACTION_MAX)
						window_voice_mute_complete(s_window_voice_mute.select_value);
					else {
						window_common_mask_except_updn_cancel_ok();
						gkt_widget_select_set_value(WIDGET_ID_SELECT, 
								gp_window_data->voice_mute_enable);
					}
				}
				else	/* return from dialog */
					gkt_window_exit();
			}
			else if(minor_type == GKT_WINDOW_UNINIT) {
				if((s_window_voice_mute.select_value < WINNDOW_SWITCH_ACTION_MAX)
					&& ((int)s_window_voice_mute.select_value != gp_window_data->voice_mute_enable)) 
				{
					gp_window_data->voice_mute_enable = (int)s_window_voice_mute.select_value;
					window_data_save();
				}
			}

			retval = GKT_EVENT_HANDLE_COMPLETE;
			break;
		case GKT_EVENT_WIDGET:
			if(minor_type == GKT_WIDGET_EVENT_CLICK) {
				s_window_voice_mute.select_value = 
					gkt_widget_select_get_value(WIDGET_ID_SELECT);
				window_voice_mute_complete(s_window_voice_mute.select_value);
				retval = GKT_EVENT_HANDLE_COMPLETE;
			}
			break;					
		default:
			break;
	}

	return retval;
}
GKT_WINDOW_DESC_DEFINE(voice_mute);
#endif

